<template>
  <el-dropdown class="dropdown" @command="handleCommand">
    <span class="el-dropdown-link">
      排序<i class="el-icon-arrow-down el-icon--right" />
    </span>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item command="justice">正序</el-dropdown-item>
      <el-dropdown-item command="reverse">倒序</el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
export default {
  name: 'PriceOrder',
  props: {
    tableData: {
      type: Array,
      default: () => []
    },
    proList: {
      type: Array,
      default: () => []
    },
    command: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      prevCommand: 'justice'
    }
  },
  mounted() {
    if (this.command) this.prevCommand = this.command
  },
  methods: {
    handleCommand(value) {
      if (this.prevCommand === value) return
      this.tableData.reverse()
      this.proList.reverse()
      this.$nextTick(() => {
        this.prevCommand = value
        this.$emit('update:command', value)
      })
    }
  }
}
</script>

<style lang='scss' scoped>
/* 价格排名下拉选择 */
.dropdown {
  position: absolute;
  right: 0px;
  top: 0;
  z-index: 90;
  color: #01c4f7;
  transform: translateX(-15px);
  &.left{
    right: 50px!important;
  }
}
.el-dropdown-menu__item {
  padding: 0 15px;
}
</style>
